"""
model name : 目标跟踪
file       : 3_数据集合成视频.py
information:
    author : OuYang
    time   : 2025/7/19
"""

import cv2
import os

# 图片文件夹路径
image_folder = 'D:/Downloads/Car24/val/images'  # 替换为你的图片文件夹路径
# 视频输出路径
video_name = 'Car24_val.avi'

# 获取所有图片文件名并按名称排序
images = [img for img in os.listdir(image_folder) if img.endswith(".png") or img.endswith(".jpg")]
images.sort()

# 读取第一张图片获取尺寸
frame = cv2.imread(os.path.join(image_folder, images[0]))
height, width, layers = frame.shape

# 定义视频编码器和帧率
video = cv2.VideoWriter(video_name, cv2.VideoWriter_fourcc(*'DIVX'), 30, (width, height))

# 将每张图片写入视频
for image in images:
    video.write(cv2.imread(os.path.join(image_folder, image)))

# 释放资源
cv2.destroyAllWindows()
video.release()
